<?php
/** 初始化项目 */
require '../../app/app.php';
/** 初始化数据库 */
use app\util\Mysql;
$database = Mysql::init();


$username = $_SESSION['username'];
$gid = $database->get("user_text", "gid", ["username" => $username]);
// if (isset($_GET["text"])) {
$text = $_GET["text"];
header('Content-Type: application/json');
$data = $database->select("text_main", ["[>]text_auth" => ["tid"]], ["tid", "textname", "creator", "created"], ["AND #0" => ["OR #1" => ["textname[~]" => $text, "main[~]" => $text], "OR #2" => ["creator" => $username, "AND #20" => ["creator[!]" => "", "gid" => $gid, "gread[!]" => "不可读"], "AND #21" => ["creator[!]" => $username, "gid[!]" => $gid, "otherread[!]" => "不可读"]], "status" => "是"]]);
$count = $database->count("text_main", ["[>]text_auth" => ["tid"]], "tid", ["AND #0" => ["OR #1" => ["textname[~]" => $text, "main[~]" => $text], "OR #2" => ["creator" => $username, "AND #20" => ["creator[!]" => "", "gid" => $gid, "gread[!]" => "不可读"], "AND #21" => ["creator[!]" => $username, "gid[!]" => $gid, "otherread[!]" => "不可读"]], "status" => "是"]]);
// $out = array("count" => $count, "data" => $data);
// echo $count;
$i=$count;
for ($i; $i > 0; $i--) {
    $time = $data[$count-$i]["created"];
    $times = new DateTime("@$time");
    $times->setTimezone(new DateTimeZone('Asia/Shanghai'));
    $times = $times->format('Y-m-d H:i:s');
    $data[$count-$i]["created"] = $times;
}
$out = array("count" => $count, "data" => $data);
// echo $times;
// $count;
// $time=$time[0]['created'];
// $date = new DateTime("@$time");
// $date->setTimezone(new DateTimeZone('Asia/Shanghai'));
// $date = $date->format('Y-m-d H:i:s');//date整理结束
// $post_text = array("textname" => $textname, "main" => $main, "creator" => $creator, "created" => $date);
// $json = json_encode(array(
//     'post_text' => $post_text
// ));
// echo $gid;
echo json_encode($out);
// }
?>